const {http,handleStr} = require("../../utils/index")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        plays:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        
          var url =  'http://47.108.197.28:3000/top/playlist/highquality';
          http({
              url,
              success:result=>{
                this.handleHttpData(result)
              }
          })
        },
    handleHttpData(result){
        var plays =[]
        result.data.playlists.forEach(item=>{
            var {name,coverImgUrl,playCount} =item;
            var play = Count(playCount);
             plays.push({
              name:handleStr(name),
              coverImgUrl,
              play
             })
            
        })
        console.log(plays)
        this.setData({
            plays
        })
        
        function Count(playCount){
                  if(playCount>10000){
                      playCount = Math.ceil(playCount/10000)+'万'
                  }
                  else if(playCount>100000000){
                      playCount = Math.floor(playCount/100000000)+'亿'
                  }
                  return playCount;
              }
    }
  

})